package bTree.LeetCode;

import java.util.LinkedList;
import java.util.List;

public class 字母大小写全排列 {
    List<String> result = new LinkedList<>();

    public List<String> letterCasePermutation(String s) {
        StringBuilder sb=new StringBuilder();
        backTracking(s,sb,0);
        return result;
    }

    private void backTracking(String s, StringBuilder sb, int index) {
        if (sb.length()==s.length()){
            result.add(sb.toString());
            return;
        }
        for (int i=index;i<s.length();i++){
            char c = s.charAt(i);
            if (c>='0'&&c<='9'){
                sb.append(c);
                backTracking(s,new StringBuilder(sb),i+1);
                sb.deleteCharAt(sb.length()-1);
            }else {
                char cc=Character.toLowerCase(c);
                sb.append(cc);
                backTracking(s,new StringBuilder(sb),i+1);
                sb.deleteCharAt(sb.length()-1);
                sb.append(Character.toUpperCase(c) );
                backTracking(s,new StringBuilder(sb),i+1);
                sb.deleteCharAt(sb.length()-1);
            }

        }
    }

}